<%@page import="java.io.IOException,java.util.*,java.util.Map.Entry" %>
<%@page import="javax.servlet.*" %>
<%@page import="com.google.appengine.api.datastore.*,com.google.appengine.api.users.*" %>
<%@page import="com.padgett.resourcemanagement.data.ClientDAO,com.padgett.resourcemanagement.util.*" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML>
<html>
<head>
<title>Performance Report</title>
<%@include file="/WEB-INF/css.jsp" %>
<style>
<!--
@page { size:11in 8.5in; margin: 0.4cm }
-->
#ReportContainer{
	margin-left: 10px;
	width:100%;
	float:left;
	clear:both;
    display:block;
    font:normal 0.75em verdana,times,serif;
    text-align:center;
}
.ContentSmallStyle{
	float:left;
	width:7%;
	height:10px;
	border:1px solid black;
	padding:3px 3px 3px 3px;
}
.LastFirstHeader{
	float:left;
	width:25%;
	height: 35px;
	border:1px solid black;
	padding:3px 3px 3px 3px;
	font-weight: bold;
}
.LastFirstContent{
	float:left;
	width:25%;
	height: 10px;
	border:1px solid black;
	padding:3px 3px 3px 3px;
}
.DateInHeader{
	float:left;
	width:8%;
	height: 35px;
	border:1px solid black;
	padding:3px 3px 3px 3px;
	font-weight: bold;
}
.DateInContent{
	float:left;
	width:8%;
	height: 10px;
	border:1px solid black;
	padding:3px 3px 3px 3px;
}
.DateInFooter{
	float:left;
	width:8%;
	height: 10px;
	border:1px solid black;
	padding:3px 3px 3px 3px;
}
.AccountantHeader{
	float:left;
	width:20%;
	height: 35px;
	border:1px solid black;
	padding:3px 3px 3px 3px;
	font-weight: bold;
}
.AccountantContent{
	float:left;
	width:20%;
	height: 10px;
	border:1px solid black;
	padding:3px 3px 3px 3px;
}
.TableSmallStyle{
	float:left;
	height:35px;
	width:7%;
	border:1px solid black;
	padding:3px 3px 3px 3px;
	font-weight: bold;
}
.LastFirstFooter{
  	float:left;
	width:25%;
	height:10px;
	border:1px solid black;
	padding:3px 3px 3px 3px;
	text-align:center;
	font-weight: bold;
}
.AccountantFooter{
  	float:left;
	width:20%;
	height:10px;
	border:1px solid black;
	padding:3px 3px 3px 3px;
	text-align:center;
	font-weight: bold;
}
.FooterSmallStyle{
	float:left;
	width:7%;
	height:10px;
	border:1px solid black;
	padding:3px 3px 3px 3px;
	text-align:center;
	font-weight: bold;
}
</style>
</head>
<body>
<% 
	Date d = new Date(System.currentTimeMillis());
%>
<h2>Personal Detail Return Report - Incomplete Family As of <%=DateUtil.formatDate(d,DateUtil.LONG_DATE_FORMAT)%></h2>
<div id="ReportContainer">
<%
UserService userService=UserServiceFactory.getUserService();
User user=userService.getCurrentUser();

// Collect all personal clients with AllFiled as false.
List<Entity> families=ClientDAO.getIncompletedFamily();
List<Entity> users=ClientDAO.getAllUsers();
Map<String,String> userMap=new HashMap<String,String>();
for(Entity accountant:users){
	userMap.put(KeyFactory.keyToString(accountant.getKey()), (String)accountant.getProperty("Nickname"));
}
%>
<!-- 
Note: Make this table and page fits landscape of a Letter Size.  11"x8.5".  Users may print this page by using browser print.

 -->
<!-- REPORT HEADER, T1 Detail Return -->
<!-- REPORT SUBHEADER, Incomplete Family -->
<!-- Table Headers: Last/First, Date In, Accountant, No of Return, No of Completed, No of Signed, No of Returned Efiled, No of Return PFiled -->
<!-- Table Footers: No of Return, No of Completed, No of Signed, No of Returned Efiled, No of Return PFiled -->
<div class="LastFirstHeader" style="background-color:#EEE">Last/First</div>
<div class="DateInHeader" style="background-color:#EEE">Date In</div>
<div class="AccountantHeader" style="background-color:#EEE">Accountant</div>
<div class="TableSmallStyle" style="background-color:#EEE">No. of <br/>Return</div>
<div class="TableSmallStyle" style="background-color:#EEE">No. of <br/>Completed</div>
<div class="TableSmallStyle" style="background-color:#EEE">No. of <br/>Signed</div>
<div class="TableSmallStyle" style="background-color:#EEE">No. of <br/>Return Efiled</div>
<div class="TableSmallStyle" style="background-color:#EEE">No. of <br/>Return Pfiled</div>

<%
// Footer counters
long numberOfReturnsFooter=0;
long numberOfReturnsCompletedFooter=0;
long numberOfReturnsSignedFooter=0;
long numberOfReturnsEFiledFooter=0;
long numberOfReturnsPaperFiledFooter=0;

// Return variables
String numberOfReturns="0";
String numberOfReturnsCompleted="0";
String numberOfReturnsSigned="0";
String numberOfReturnsEFiled="0";
String numberOfReturnsPaperFiled="0";
for(Entity family:families){
	/**
	The following are variables that will be printed using scriptlet.  All calculations or text manipulations will be done in this section.
	*/
	String lastFirst=(String)(family.getProperty("LastName")!=null?family.getProperty("LastName"):"")+("/"+(String)((family.getProperty("FirstName")!=null?family.getProperty("FirstName"):"")));
	String dateIn=(family.getProperty("DateIn")!=null?DateUtil.formatDate(((Date)(family.getProperty("DateIn"))), DateUtil.SHORT_DATE_FORMAT):"");
	String accountant=(family.getProperty("Accountant")!=null?((userMap.get((String)family.getProperty("Accountant")))):"");
	if(family.getProperty("NumberOfReturns")!=null){
		numberOfReturnsFooter+=(Long)family.getProperty("NumberOfReturns");
		numberOfReturns=((Long)family.getProperty("NumberOfReturns")).toString();
	}else{
		numberOfReturns="";
	}
	if(family.getProperty("NumberOfReturnsCompleted")!=null){
		numberOfReturnsCompletedFooter+=(Long)family.getProperty("NumberOfReturnsCompleted");
		numberOfReturnsCompleted=((Long)family.getProperty("NumberOfReturnsCompleted")).toString();
	}else{
		numberOfReturnsCompleted="";
	}
	if(family.getProperty("NumberOfReturnsSigned")!=null){
		numberOfReturnsSignedFooter+=(Long)family.getProperty("NumberOfReturnsSigned");
		numberOfReturnsSigned=((Long)family.getProperty("NumberOfReturnsSigned")).toString();
	}else{
		numberOfReturnsSigned="";
	}
	if(family.getProperty("NumberOfReturnsEFiled")!=null){
		numberOfReturnsEFiledFooter+=(Long)family.getProperty("NumberOfReturnsEFiled");
		numberOfReturnsEFiled=((Long)family.getProperty("NumberOfReturnsEFiled")).toString();
	}else{
		numberOfReturnsEFiled="";
	}
	if(family.getProperty("NumberOfReturnsPaperFiled")!=null){
		numberOfReturnsPaperFiledFooter+=(Long)family.getProperty("NumberOfReturnsPaperFiled");
		numberOfReturnsPaperFiled=((Long)family.getProperty("NumberOfReturnsPaperFiled")).toString();
	}else{
		numberOfReturnsPaperFiled="";
	}
%>
<div class="LastFirstContent" style="clear:both;"><%=lastFirst %></div>
<div class="DateInContent"><%=dateIn %></div>
<div class="AccountantContent"><%=accountant %></div>
<div class="ContentSmallStyle"><%=numberOfReturns %></div>
<div class="ContentSmallStyle"><%=numberOfReturnsCompleted %></div>
<div class="ContentSmallStyle"><%=numberOfReturnsSigned %></div>
<div class="ContentSmallStyle"><%=numberOfReturnsEFiled %></div>
<div class="ContentSmallStyle"><%=numberOfReturnsPaperFiled %></div>
<%
}
%>
<!-- Output Footers here using footer variables, e.g. numberOfReturnsFooter. -->
<div class="LastFirstFooter" style="clear:both;background-color:#EEE">&nbsp;</div>
<div class="DateInFooter" style="background-color:#EEE">&nbsp;</div>
<div class="AccountantFooter" style="background-color:#EEE">Total</div>
<div class="FooterSmallStyle" style="background-color:#EEE"><%=numberOfReturnsFooter %></div>
<div class="FooterSmallStyle" style="background-color:#EEE"><%=numberOfReturnsCompletedFooter %></div>
<div class="FooterSmallStyle" style="background-color:#EEE"><%=numberOfReturnsSignedFooter %></div>
<div class="FooterSmallStyle" style="background-color:#EEE"><%=numberOfReturnsEFiledFooter %></div>
<div class="FooterSmallStyle" style="background-color:#EEE"><%=numberOfReturnsPaperFiledFooter %></div>
</div>
</body>
</html>